Passed
Branch dev (0fab21)
by Salim
05:13
created

main.js ➔ testDatabaseConnection   B

Complexity

Conditions 6

Size

Total Lines 46
Code Lines 36

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 36
dl 0
loc 46
c 0
b 0
f 0
cc 6
rs 8.0826
1
function textboxOnFocus(key){
2
    $("#notes_message").attr("style", "display:none;");
3
    $('#'+key).show();
4
	//$('#'+key).fadeIn('slow');
5
}
6
7
function textboxOnBlur(key){
8
    $("#"+key).attr("style", "display:none;");
9
}
10
11
function setFocus(key){
12
	$("#"+key).focus();
13
}
14
15
function testDatabaseConnection(){    
16
	
17
	$('.loading_img').show();
18
	$('#notes_message').attr("style", "display:none;");
19
	buttonDisable();
20
	
21
	var database_host = $("#database_host").val();
22
	var database_name = $("#database_name").val();
23
	var database_username = $("#database_username").val();
24
	var database_password = $("#database_password").val();
25
	var database_ssl = $("#database_ssl").is(':checked') ? 1 : 0;
26
	
27
	$.ajax({
28
		url: "ajax/handler.ajax.php",
29
		global: false,
30
		type: "POST",
31
		data: ({db_host:database_host,
32
			    db_name:database_name,
33
				db_username:database_username,
34
				db_password:database_password,
35
				db_ssl:database_ssl,
36
				check_key : "apphpei"
37
		}),
38
		dataType: "html",
39
		async:false,
40
		error: function(html){
41
			$('.loading_img').hide();
42
            $("#notes_message").html(EasyInstaller._MSG["ajax_connection_error"]);
43
		},
44
		success: function(html){
45
			var obj = jQuery.parseJSON(html);
46
			if(obj.status == "1"){
47
				if(obj.db_connection_status == "1"){
48
					$("#notes_message").html("<h4 class='success'>"+EasyInstaller._MSG["success"]+"</h4><p>"+EasyInstaller._MSG["db_version"]+": "+obj.db_version+"</p><p>"+EasyInstaller._MSG["connection_was_established"]+"</p>");	
49
				}else{
50
					$("#notes_message").html("<h4>"+EasyInstaller._MSG["error"]+"</h4><p>"+obj.db_error+"</p>");	
51
				}                
52
			}else{
53
                $("#notes_message").html("<span class='msg_error'>"+EasyInstaller._MSG["connection_error"]+"</span>");
54
			}			
55
		}
56
	});
57
	$('.loading_img').hide();
58
	$('#notes_message').fadeIn();
59
	buttonEnable();
60
}
61
62
function buttonDisable(){	
63
	$("#button_test").attr("style", "cursor:default;");	
64
}
65
66
function buttonEnable(){
67
	$("#button_test").attr("style", "cursor:pointer;");
68
}
69
70
function installTypeOnClick(val){
71
	if(val == "un-install"){
72
		$("#line_admin_info").hide("fast");
73
		$("#line_admin_login").hide("fast");
74
		$("#line_admin_password").hide("fast");
75
		$("#line_password_encryption").hide("fast");
76
	}else{
77
		$("#line_admin_info").show("fast");
78
		$("#line_admin_login").show("fast");
79
		$("#line_admin_password").show("fast");
80
		$("#line_password_encryption").show("fast");	
81
	}
82
}
83
84
/**
85
 *   Change location 
86
 */
87
function goTo(page){
88
    window.location.href = page;
89
}
90